/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-05 19:48:15
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-08 08:15:45
 * @FilePath: \vue3_admin_template\project\src\api\product\spu\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%
 */
//spu管理模块的接口
import request from '@/utils/request'
import type {
  HasSpuResponseData,
  AllTradeMark,
  SpuHasImg,
  SaleAttrResponseData,
  HasScaleAttrResponseData,
  SkuData,
  SkuInfoData,
} from './type'
enum API {
  //获取已有的SPU的数据
  HASSPU_URL = '/admin/product',
  //获取全部品牌数据
  ALLTRADMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  //获取某一个SPU下的全部售卖商品图片的数据
  IMAGE_URL = '/admin/product/spuImageList/',
  //获取某一个spu下全部的已有的销售属性接口地址
  SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
  //获取全部销售属性[颜色 版本 尺码]
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',

  //添加一个新SPU数据
  ADDSPRU_URL = '/admin/product/saveSpuInfo',
  //更新已有的SPU
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  //追加一个新的SKU地址
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  //查看某一个已有的SPU下的全部售卖商品
  SKUINFO_URL = '/admin/product/findBySpuId/', //{SpuId}
  //删除已有SPU
  REMOVESPU_URL = '/admin/product/deleteSpu/', //{SpuId}
}

//获取某一个三级分类下的已有的SPU数据
export const reqHasSpu = (
  page: number,
  limit: number,
  category3Id: number | string,
) =>
  request.get<any, HasSpuResponseData>(
    API.HASSPU_URL + `/${page}/${limit}?category3Id=${category3Id}`,
  )
//获取全部SPU的品牌的数据
export const reqAllTradeMark = () =>
  request.get<any, AllTradeMark>(API.ALLTRADMARK_URL)
//获取某一个已有的SPU下的全部的商品的图片地址
export const reqSpuImageList = (spuId: number) =>
  request.get<any, SpuHasImg>(API.IMAGE_URL + `${spuId}`)
//获取某一个已有的SPU拥有对少个销售属性
export const reqSpuHasSaleAttr = (spuId: number) =>
  request.get<any, SaleAttrResponseData>(API.SPUHASSALEATTR_URL + `${spuId}`)
//获取全部销售属性
export const reqAllSaleAttr = () =>
  request.get<any, HasScaleAttrResponseData>(API.ALLSALEATTR_URL)

//添加一个新的SPU
export const reqAddOrUpdateSpu = (data: any) => {
  //data有souId
  if (data.id) {
    //更新
    request.post(API.UPDATESPU_URL, data)
  } else {
    //添加
    request.post(API.ADDSPRU_URL, data)
  }
}

//追加一个新的SKU方法
export const reqAddSku = (data: SkuData) =>
  request.post<any, any>(API.ADDSKU_URL, data)
//获取SPU数据
export const reqSkuList = (spuId: number | string) =>
  request.get<any, SkuInfoData>(API.SKUINFO_URL + `${spuId}`)
//删除SPU的方法
export const reqRemoveSpu = (spuId: number | string) =>
  request.delete<any, any>(API.REMOVESPU_URL + `${spuId}`)
